﻿@model MessageModel
@{
    ViewBag.Title = "If";
}

<h2>If</h2>

<p>The if binding causes a section of markup to appear in your document (and to have its data-bind attributes applied), only if a specified expression evaluates to true (or a true-ish value such as a non-null object or nonempty string).</p>
<p><a href="http://knockoutjs.com/documentation/if-binding.html" target="_blank">http://knockoutjs.com/documentation/if-binding.html</a></p>


<p>Click on the checkbox to see example of the "If" function in action</p>

@Html.VisiTogglerFromPartial(CodeSamplePartials.IF_VIEW_MODEL, Html.CreateVisiToggler("show the samples view model C# source code ", htmlAttributes: new { @class = "onright" }, options: VisiOptions.HiddenByDefault))

<label>
    <input type="checkbox" @Html.KoAttrChecked(m => m.displayMessage) />
    Display message</label>

<h3>Sample #1</h3>

<p>Using data-bind attribute</p>

<div @Html.KoAttrIf(m => m.displayMessage)>Here is a <b>checked</b> message. Astonishing.</div>

@Html.VisiTogglerFromPartial(CodeSamplePartials.IF1, Html.CreateVisiToggler("show the sample source code ", htmlAttributes: new { @class = "onright" }, options: VisiOptions.HiddenByDefault))

<h3>Sample #2</h3>

<p>Containerless control flow syntax</p>

@using (Html.KoIf(m => !m.displayMessage))
{
    <div>Here is a <b>NOT checked</b> message. Astonishing.</div>
}

@Html.VisiTogglerFromPartial(CodeSamplePartials.IF2, Html.CreateVisiToggler("show the sample source code ", htmlAttributes: new { @class = "onright" }, options: VisiOptions.HiddenByDefault))

<p>&nbsp;</p>
<p>Next &gt; @Html.ActionLink("Ifnot", "Ifnot", "Examples")</p>

@Model.ApplyBindingsScript()